// pages/biz/bindPhone/bingPhone.js
//引入请求接口文件
import Serv from './paySendMsgServ';
import Config from "../../../../utils/config2.js";
var regeneratorRuntime = require("../../../../lib/js/runtime-module.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    time: '获取验证码',
    currentTime: 60,
    disabled: false,
    verifyCode:'',
    options:{},
    
  },
  formSubmit: function (e) {
    let walletInfo = wx.getStorageSync('walletInfo')||{};
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    if (e.detail.value.verifyCode==''){
      wx.showToast({
        title: '验证码不能为空',
        icon:"none"
      })
      return false
    }
    let {options} = this.data
    
    let params = { ...options, ...e.detail.value,name:walletInfo.name, accountId:walletInfo.llWalletId?walletInfo.llWalletId:wx.getStorageSync(Config.userIdKey), paymentType:this.flag(this.data.action)}//todo 删除accountId
    delete params.action
    this.setData({
      disabled: true
    })
    this.tradeSecondSmsValid(params,(data)=>{
      console.log(data)
      //报名费 （前端逻辑 1:秒杀=>提交报名费 ; 2:秒杀=>支付定金 ; 3:竞拍=>支付报名费 ; 4:竞拍=>支付定金）isStartActivity 1 为开始 2 为未开始  
        this.setData({
          disabled: false
        })
        if(data.success){
          console.log(this.data.action)

          if (this.data.action == 1) {
            let imgurls = data.data.imageUrls,
              tags = data.data.tags ? JSON.stringify(data.data.tags) : ''
            wx.redirectTo({
              url: `../../kill/qualify/qualify?time=${data.data.startTime}&price=${data.data.totalAmount}&id=${data.data.seckillProductId}&name=${data.data.projectName}&detail=${data.data.detail}&imgUrls=${imgurls ? imgurls[0] : ''}&provinceName=${data.data.provinceName}&cityName=${data.data.cityName}&tags=${tags ? tags : ''}&productId=${data.data.productId}&promotionDetail=${data.data.promotionDetail}`,
            })
          } else if (this.data.action == 2) {
            let imgurls = data.data.imageUrls,
              tags = data.data.tags ? JSON.stringify(data.data.tags) : ''
            wx.redirectTo({
              url: `/subPackages2/pages/pay/paySuccess/paySuccess?actionType=1&price=${data.data.totalAmount}&orderId=${data.data.seckillOrderId}&mobile=${data.data.consultantMobile}&id=${data.data.seckillProductId}&imgUrls=${imgurls ? imgurls[0] : ''}&projectName=${data.data.projectName}&detail=${data.data.detail}&provinceName=${data.data.provinceName}&cityName=${data.data.cityName}&tags=${tags ? tags : ''}&productId=${data.data.productId}&promotionDetail=${data.data.promotionDetail}`,
            })
          } else if (this.data.action == 3){
            let imgurls = data.data.imageUrls,
              tags = data.data.tags ? JSON.stringify(data.data.tags) :''
            wx.reLaunch({
              url: `/subPackages2/pages/pay/paySuccess/paySuccess?actionType=2&time=${data.data.isStartActivity == 1 ? data.data.startTime : data.data.endTime}&price=${data.data.totalAmount}&id=${data.data.seckillProductId}&isStartActivity=${data.data.isStartActivity}&name=${data.data.name}&imgUrls=${imgurls ? imgurls[0] : ''}&projectName=${data.data.projectName}&detail=${data.data.detail}&provinceName=${data.data.provinceName}&cityName=${data.data.cityName}&tags=${tags ? tags : ''}&productId=${data.data.productId}&promotionDetail=${data.data.promotionDetail}`,
              
            })
            console.log(tags)
          }else if(this.data.action == 4){
            let imgurls = data.data.imageUrls,
              tags = data.data.tags ? JSON.stringify(data.data.tags) : ''
          
            wx.reLaunch({
              url: `/subPackages2/pages/pay/paySuccess/paySuccess?actionType=4&time=${data.data.startTime}&price=${data.data.totalAmount}&orderId=${data.data.seckillOrderId}&mobile=${data.data.consultantMobile}&id=${data.data.seckillProductId}&name=${data.data.name}&imgUrls=${imgurls ? imgurls[0] : ''}&projectName=${data.data.projectName}&detail=${data.data.detail}&provinceName=${data.data.provinceName}&cityName=${data.data.cityName}&tags=${tags ? tags : ''}&productId=${data.data.productId}&promotionDetail=${data.data.promotionDetail}`,
            })
          }
        }else{
          wx.showToast({
            title: data.msg,
            icon: 'none'
          })
        }
    })
  },
  formReset: function () {
    console.log('form发生了reset事件')
  },
  //二次支付
  async tradeSecondSmsValid(parmas,cbk) {
    let data  = await Serv.tradeSecondSmsValid(parmas)
    cbk&&cbk(data)
  },
  //判断报名费或定金(后端按金额分类逻辑，1，竞拍报名费/秒杀报名费；2，定金)（前端逻辑 1:秒杀=>提交报名费 ; 2:秒杀=>支付定金 ; 3:竞拍=>支付报名费 ; 4:竞拍=>支付定金）
  flag(item) {
    if (item == 3 || item == 1) {
      return 1
    } else if (item == 2 || item == 4) {
      return 2
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.setData({
      action: options.action,
      options
    })
    
    console.log(this.data)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {


  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})